package practises;

public class Num1 {

    public ListNode removeElements(ListNode head, int val) {

         if(head == null) {
             return null;
         }
         while(head.val == val) {
             head = head.next;
         }
         ListNode prev = head;
         while(prev.next != null) {
             if(prev.next.val == val) {
                 prev.next = prev.next.next;
                 continue;
             }
             prev = prev.next;
         }
         return head;
    }
}
